home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Laser.lua < prev    next >
Text File  |  2010-09-23  |  6KB  |  174 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Laser + Projectile Ray
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.laser={}
  10. cc.laser.ray={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.laser.gfx_wpn=loadgfx("weapons/laser.bmp")                    -- Weapon Image
  14. setmidhandle(cc.laser.gfx_wpn)
  15. cc.laser.gfx_pro=loadgfx("weapons/lasershot.png")                -- Projectile Image
  16. setmidhandle(cc.laser.gfx_pro)
  17. cc.laser.sfx_attack=loadsfx("laser.wav")                        -- Attack Sound
  18. cc.laser.sfx_impact=loadsfx("laserimpact.wav")                    -- Impact Sound
  19.  
  20. --------------------------------------------------------------------------------
  21. -- Weapon: Laser
  22. --------------------------------------------------------------------------------
  23.  
  24. cc.laser.id=addweapon("cc.laser","Laser",cc.laser.gfx_wpn,3)    -- Add Weapon (3 uses)
  25. cc.laser.ammo=5                                                    -- 5 Rays
  26.  
  27. function cc.laser.draw()                                        -- Draw
  28.     setblend(blend_alpha)
  29.     setalpha(1)
  30.     setcolor(255,255,255)
  31.     drawinhand(cc.laser.gfx_wpn,6,0)
  32.     -- HUD ammobar
  33.     if cc.laser.ammo-weapon_shots>0 then
  34.         hudammobar(cc.laser.ammo-weapon_shots,cc.laser.ammo)
  35.     end
  36.     -- HUD Crosshair
  37.     if cc.laser.ammo-weapon_shots>0 then
  38.         hudcrosshair(7,3)
  39.     end
  40. end
  41.  
  42. function cc.laser.attack(attack)                                -- Attack
  43.     -- Decrement timer
  44.     if weapon_timer>0 then
  45.         weapon_timer=weapon_timer-1
  46.     end
  47.     -- Attack
  48.     if weapon_shots<cc.laser.ammo and weapon_timer<=0 and attack==1 then
  49.         -- No more weapon switching!
  50.         useweapon(0)
  51.         -- Reset Timer
  52.         weapon_timer=15
  53.         -- Attack
  54.         playsound(cc.laser.sfx_attack)
  55.         weapon_shots=weapon_shots+1
  56.         id=createprojectile(cc.laser.ray.id)
  57.         projectiles[id]={}
  58.         -- Ignore collision with current player at beginning
  59.         projectiles[id].ignore=playercurrent()
  60.         -- Set initial position of projectile
  61.         projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
  62.         projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
  63.         -- Set speed of projectile
  64.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*15.0
  65.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*15.0
  66.         -- Timer
  67.         projectiles[id].timer=0
  68.         -- Initial movement
  69.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  70.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  71.         for i=1,3,1 do
  72.             if cc.laser.ray.move(id)==1 then
  73.                 break
  74.             end
  75.         end
  76.         -- Effects
  77.         recoil(3)
  78.         particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
  79.         particlecolor(255,0,0)
  80.         particlefadealpha(0.01)
  81.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
  82.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  83.         particlefadealpha(0.005)
  84.         -- End Turn
  85.         if (weapon_shots>=cc.laser.ammo) then
  86.             endturn()
  87.         end
  88.     end
  89. end
  90.  
  91. --------------------------------------------------------------------------------
  92. -- Projectile: Ray
  93. --------------------------------------------------------------------------------
  94.  
  95. cc.laser.ray.id=addprojectile("cc.laser.ray")            -- Add Projectile
  96.  
  97. function cc.laser.ray.draw(id)                            -- Draw
  98.     -- Setup draw mode
  99.     setblend(blend_light)
  100.     setalpha(1)
  101.     setcolor(255,0,0)
  102.     setscale(0.5,1)
  103.     -- Calculate projectile rotation
  104.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  105.     -- Draw projectile
  106.     drawimage(cc.laser.gfx_pro,projectiles[id].x,projectiles[id].y)
  107.     -- Draw Arrow if out of Screen
  108.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  109. end
  110.  
  111. function cc.laser.ray.update(id)                        -- Update
  112.     -- Move
  113.     cc.laser.ray.move(id)
  114. end
  115.  
  116. function cc.laser.ray.move(id)
  117.     -- Timer (free after 10 secs)
  118.     projectiles[id].timer=projectiles[id].timer+1
  119.     if projectiles[id].timer>500 then
  120.         -- Free projectile
  121.         freeprojectile(id)
  122.         return 1
  123.     end
  124.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  125.     -- Move (in substep loop for optimal collision precision)
  126.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  127.     msubx=projectiles[id].sx/msubt
  128.     msuby=projectiles[id].sy/msubt
  129.     for i=1,msubt,1 do
  130.         projectiles[id].x=projectiles[id].x+msubx
  131.         projectiles[id].y=projectiles[id].y+msuby        
  132.         -- Collision
  133.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)==1 then
  134.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  135.                 -- Cause damage
  136.                 if playercollision()~=0 and playercollision()~=projectiles[id].ignore then
  137.                     playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
  138.                     playerdamage(playercollision(),6)
  139.                     blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
  140.                 elseif objectcollision()>0 then
  141.                     objectdamage(objectcollision(),6)
  142.                 end
  143.                 -- Destroy terrain
  144.                 terraincircle(projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21,7,0x00000000)
  145.                 -- Effects
  146.                 playsound(cc.laser.sfx_impact)
  147.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  148.                 particlefadealpha(0.006)
  149.                 particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  150.                 particlecolor(255,0,0)
  151.                 particlefadealpha(0.01)
  152.                 for i=1,3 do
  153.                     particle(p_spark,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  154.                     particlecolor(255,0,0)
  155.                     particlefadealpha(0.004)
  156.                 end
  157.                 -- Free projectile
  158.                 freeprojectile(id)
  159.                 return 1
  160.             end
  161.         else
  162.             projectiles[id].ignore=0
  163.         end
  164.         -- Water
  165.         if (projectiles[id].y)>getwatery()+5 then
  166.             -- Effects
  167.             playsound(cc.laser.sfx_impact)
  168.             particle(p_smoke,projectiles[id].x,projectiles[id].y)
  169.             -- Free projectile
  170.             freeprojectile(id)
  171.             return 1
  172.         end
  173.     end
  174. end